//
//  StatusesViewModel.swift
//  WeiBo
//
//  Created by 陈贵 on 15/9/12.
//  Copyright © 2015年 hzj. All rights reserved.
//

import UIKit

class StatusesViewModel: NSObject {
    
 /// 转发微博文字
    var retweetedText:String?{
        let name = statuses.retweeted_status?.user?.name ?? ""
        let text = statuses.retweeted_status?.text ?? ""
        return "@\(name):\(text)"
    }
    
 /// 记录使用的 cell
    var cellID:String{
        return statuses.retweeted_status == nil ? HZJNormalCellID : HZJRetweetedCellID
    }
    
    
    /// 当前模型对应的行高
    var rowHeight: CGFloat = 0

    
    /// 微博对象
    var statuses :Statuses
    /// 用户头像
    var userIconUrl: NSURL?{
        return NSURL(string:statuses.user?.profile_image_url ?? " ")
    }
    /// VIP图像
    var userVipImage: UIImage?{
        switch (statuses.user?.verified ?? -1){
        case 0: return UIImage(named: "avatar_vip")
        case 2,3,5: return UIImage(named: "avatar_enterprise_vip")
        case 220:return UIImage(named: "avatar_grassroot")
        default: return nil
        }
    }
    /// 会员等级 1-6
    var userMemberImage: UIImage?{
        if statuses.user?.mbrank > 0 && statuses.user?.mbrank < 7{
         return UIImage(named: "common_icon_membership_level\(statuses.user?.mbrank)")
        }
        return nil
    }
    
    /// 配图缩略图 URL 数组
    var thumbnailURLs: [NSURL]?
    
      init(statuses:Statuses) {
        self.statuses = statuses

//        if statuses.pic_urls != nil{
//            thumbnailURLs = [NSURL]()
//            for dic in statuses.pic_urls!{
//                thumbnailURLs?.append(NSURL(string: dic["thumbnail_pic"]!)!)
//            }
//            
//        }
//        if statuses.retweeted_status?.pic_urls != nil{
//            thumbnailURLs = [NSURL]()
//            for dic in statuses.retweeted_status!.pic_urls! {
//                thumbnailURLs?.append(NSURL(string: dic["thumbnail_pic"]!)!)
//            }
//        }
        
        
        //将前面两段代码和为一
        if let thing = statuses.pic_urls ?? statuses.retweeted_status?.pic_urls {
            thumbnailURLs = [NSURL]()
            for dict in thing {
                thumbnailURLs?.append(NSURL(string: dict["thumbnail_pic"]!)!)
            }
        }
        super.init()
    }
    override var description:String {
        return statuses.description + " 缩略图 URL 数组 \(thumbnailURLs)"
    }
    
    
}
